import {
  $authorization,
  $callList,
  $giftAnim,
  $inviteConfirm,
  $loading,
  $message,
  $redPackets,
  $scorllMessage,
  $signinValiation,
  $tips
} from "@/utils/components-proxy";
import { PageOptions, data, page } from "@/library/lib";
import { MiniService } from "../../services/MiniService";
import { using } from "@/library/injector";
import { $errTip } from "@/utils/error-handler";



/**
 * Page - index
 * @create 2020-07-10 00:00:00
 * @author Halo
 *
 */

@page
export default class extends PageOptions {
  @using("MiniService") miniService: MiniService;
  @data anchor: any = null
  /* 页面加载回调 */
  async onLoad(query: Record<string, string | undefined>) {
  }
  async onShow() {
    this.miniService.anchorData().then(res => {
      console.log(res)
      this.setData({
        'anchor.hot': res.hot,
        'anchor.rank': res.rank
      })
    })
    let _this = this;
    wx.getStorage({
      key: "anchor",
      success(data) {
        console.log(data.data)
        _this.setData({
          anchor: data.data
        })
      }
    })
  }
  async onHide() {
  }
  onUnload() {
  }
  onShareAppMessage(res: any): WechatMiniprogram.Page.ICustomShareContent {
    return {
      title: "title",
      path: "/pages/index/index",
      imageUrl: "$assets/imgs/ad-swiper/swiper-1.png"
    };
  }
  vote() {
    let _this = this
    this.miniService.voteAnchor().then(res => {
      console.log(res)
      console.log(`成功为${_this.data.anchor.name}打call一次`)
      let content = `成功为${_this.data.anchor.name}打call一次`
      $message.msg({
        title: "恭喜你",
        content
      })
      this.setData({
        'anchor.hot': res.data.anchorHot,
        'anchor.rank': res.data.anchorRank
      })
    }).catch(() => {
      $message.msg({
        title: "提示",
        content: "您的❤数量不足"
      })
    })
  }
}
